<?php

namespace Phones\MainBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Models
 *
 * @ORM\Table(name="models", indexes={@ORM\Index(name="IDX_E4D6300944F5D008", columns={"brand_id"})})
 * @ORM\Entity(repositoryClass="ModelRepository")
 */
class Model extends BaseEntity {

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    public $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=100, nullable=false)
     */
    public $name;

    /**
     * @var string
     *
     * @ORM\Column(name="image", type="string", length=100, nullable=true)
     */
    public $image;

    /**
     * @var float
     *
     * @ORM\Column(name="price", type="float", precision=10, scale=0, nullable=true)
     */
    public $price;

    /**
     * @var string
     *
     * @ORM\Column(name="package", type="string", length=255, nullable=true)
     */
    public $package;

    /**
     * @var string
     *
     * @ORM\Column(name="case", type="string", length=100, nullable=true)
     */
    public $case;

    /**
     * @var string
     *
     * @ORM\Column(name="battery_type", type="string", length=100, nullable=true)
     */
    public $batteryType;

    /**
     * @var string
     *
     * @ORM\Column(name="battery_capacity", type="string", length=100, nullable=true)
     */
    public $batteryCapacity;

    /**
     * @var string
     *
     * @ORM\Column(name="display_type", type="string", length=100, nullable=true)
     */
    public $displayType;

    /**
     * @var string
     *
     * @ORM\Column(name="display_size", type="string", length=100, nullable=true)
     */
    public $displaySize;

    /**
     * @var string
     *
     * @ORM\Column(name="display_resolution", type="string", length=100, nullable=true)
     */
    public $displayResolution;

    /**
     * @var string
     *
     * @ORM\Column(name="camera_size", type="string", length=100, nullable=true)
     */
    public $cameraSize;

    /**
     * @var string
     *
     * @ORM\Column(name="camera_resolution", type="string", length=100, nullable=true)
     */
    public $cameraResolution;

    /**
     * @var string
     *
     * @ORM\Column(name="camera_other", type="string", length=100, nullable=true)
     */
    public $cameraOther;

    /**
     * @var string
     *
     * @ORM\Column(name="sound_melody_type", type="string", length=100, nullable=true)
     */
    public $soundMelodyType;

    /**
     * @var string
     *
     * @ORM\Column(name="sound_other", type="string", length=100, nullable=true)
     */
    public $soundOther;

    /**
     * @var string
     *
     * @ORM\Column(name="memory_internal", type="string", length=100, nullable=true)
     */
    public $memoryInternal;

    /**
     * @var string
     *
     * @ORM\Column(name="memory_card", type="string", length=100, nullable=true)
     */
    public $memoryCard;

    /**
     * @var string
     *
     * @ORM\Column(name="memory_ram", type="string", length=100, nullable=true)
     */
    public $memoryRam;

    /**
     * @var string
     *
     * @ORM\Column(name="software", type="string", length=100, nullable=true)
     */
    public $software;

    /**
     * @var string
     *
     * @ORM\Column(name="data", type="string", length=100, nullable=true)
     */
    public $data;

    /**
     * @var \Brands
     *
     * @ORM\ManyToOne(targetEntity="Brand")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="brand_id", referencedColumnName="id")
     * })
     */
    public $brand;

    public function getImage() {
        return "img/models/{$this->brand->name}/{$this->name}.jpg";
    }

    public function withUnit($field, $unitName = null) {
        $val = $this->$field;
        if (! empty($val)) {
            $unitName = empty($unitName) ? $field : $unitName;
            $units    = $this->getParameter('unit');
            if (isset($units[$unitName])) {
                $val .= '<span class="unit">' . $this->translate($units[$unitName]) . '</span>';
            }
        }

        return $val;
    }
}
